userStatus = {
	url: updateUserStatusUrl,
	cycle_time: 0,
	update: function(url) {
		$.ajax({
			url: url,
			dataType: 'html',
			success: function(data) {
				if (data != '') {
					$('#jsCoursePending').html(data);
				}
			}
		})
	},
	init: function(url, cycleTime) {
		this.url = url;
		this.cycle_time = cycleTime;
		setInterval(userStatus.update, this.cycle_time * 60000, this.url);
	}
}
$(function() {
	$('.filter .type').click(function() {
		$(this).closest('li').toggleClass('open');
		return false;
	});
	$('input[type=image], img').each (function() {
		var src = $(this).attr('src');
		if (src.match('_off')) {
			$(this).mouseover(function() {
				var src = $(this).attr('src');
				$(this).attr('src', src.replace('_off', '_on'));
			});
			$(this).mouseout(function() {
				var src = $(this).attr('src');
				$(this).attr('src', src.replace('_on', '_off'));
			});
		}
	});
	$('#top,#top2').click(function() {
		$('html,body').animate({scrollTop: 0});
		return false;
	});
	if ($(body).height() <= $(window).height()) {
		$('#top,#top2').hide();
	}

	$('#imageList img').on('click', function(){
		var imageUrl = $(this).attr('src');
		$('#largeImage').attr('src', imageUrl);
	});

	if ($('#jsEnterCourse').length > 0) {
		$('#jsEnterCourse').click(function() {
			$('#jsJoiningCourse').submit();
			return false;
		});
	}
	bindDetailSelect();
	$('.smallImage').click(function() {
		$('#largeImage').attr('src', $(this).attr('src'));
		return false;
	});
	$('.btnReset').click(function() {
		$(this).closest('form').get(0).reset();
		return false;
	});
	$('#step01 .btnSubmit').click(function() {
		$('#step01').hide();
		$('#step02').show();
		return false;
	});
	$('#step02 .btnReset').click(function() {
		$('#step02').hide();
		$('#step01').show();
		return false;
	});
	$('.jsBtnBack').unbind('click').click(function() {
		window.history.back();
		return false;
	});
	$('.username').click(function() {
		$(this).closest('li').toggleClass('open');
		return false;
	});
	userStatus.init(updateUserStatusUrl, userStatusExpireTime);
});
function bindDetailSelect() {
	if ($('#jsDetailList').length > 0) {
		$('#jsDetailList').change(function() {
			var that = $(this);
			var optionsHtml = that.html();
			console.log(optionsHtml);
			var detailId = that.val();
			$.ajax({
				url: ajaxCourseDetail,
				data: {detail: detailId},
				dataType: 'html',
				success: function(data) {
					$('#jsCourseSchedule').html(data);
					$('#jsDetailList').html(optionsHtml);
					$('#jsDetailList').children('option').removeAttr('selected');
					$('#jsDetailList').children('option[value='+detailId+']').attr('selected', 'selected');
					bindDetailSelect();
				},
				beforeSend: function(xhr) {
					that.attr('disabled', 'disabled');
				},
				complete: function() {
					that.removeAttr('disabled');
				}
			});
		});
	}
}
$(window).load(function() {
	$('#slider').nivoSlider({
		effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
		slices: 15, // For slice animations
		boxCols: 8, // For box animations
		boxRows: 4, // For box animations
		animSpeed: 500, // Slide transition speed
		pauseTime: 3000, // How long each slide will show
		startSlide: 0, // Set starting Slide (0 index)
		directionNav: false, // Next & Prev navigation
		controlNav: true, // 1,2,3... navigation
		controlNavThumbs: false, // Use thumbnails for Control Nav
		pauseOnHover: true, // Stop animation while hovering
		manualAdvance: false, // Force manual transitions
		prevText: 'Prev', // Prev directionNav text
		nextText: 'Next', // Next directionNav text
		randomStart: false, // Start on a random slide
		beforeChange: function(){}, // Triggers before a slide transition
		afterChange: function(){}, // Triggers after a slide transition
		slideshowEnd: function(){}, // Triggers after all slides have been shown
		lastSlide: function(){}, // Triggers when last slide is shown
		afterLoad: function(){} // Triggers when slider has loaded
	});
});